package pojo.bean;

import java.util.List;
import java.util.Objects;

import org.json.JSONObject;

public class TreeNode {
    private int id;
    private String text;
    private String state;
    private List<JSONObject> children;

    public TreeNode() {}

    public TreeNode(int id, String text, String state, List<JSONObject> children) {
        this.id = id;
        this.text = text;
        this.state = state;
        this.children = children;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        String checked =  TreeNodeStateEnum.CHECKED.getState();
        String unchecked = TreeNodeStateEnum.UNCHECKED.getState();
        String indeterminate = TreeNodeStateEnum.INDETERMINATE.getState();
        if (Objects.equals(state, checked)) {
            this.state = checked;
        } else if (Objects.equals(state, unchecked)) {
            this.state = unchecked;
        } else if (Objects.equals(state, indeterminate)) {
            this.state = indeterminate;
        } else {
            this.state = checked;
        }
    }

    public List<JSONObject> getChildren() {
        return children;
    }

    public void setChildren(List<JSONObject> children) {
        this.children = children;
    }
}
